package com.lagou.demo.controller;

import com.lagou.demo.service.IDemoService;
import com.lagou.edu.mvcframework.annotations.LagouAutowired;
import com.lagou.edu.mvcframework.annotations.LagouController;
import com.lagou.edu.mvcframework.annotations.LagouRequestMapping;
import com.lagou.edu.mvcframework.annotations.LagouSecurity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

@LagouSecurity(value = {"张三","李四","王五"})
@LagouController
@LagouRequestMapping("/demo")
public class DemoController {


    @LagouAutowired
    private IDemoService demoService;


    /**
     * URL: /demo/query?name=lisi
     * @param request
     * @param response
     * @param name
     * @return
     */
    @LagouSecurity(value = {"joey"})
    @LagouRequestMapping("/query")
    public String query(HttpServletRequest request, HttpServletResponse response,String name) {
        return demoService.get(name);
    }

    @LagouSecurity(value = {"zhangsan","lisi"})
    @LagouRequestMapping("/test")
    public String test(HttpServletResponse response,HttpServletRequest request,String username) throws IOException {

            response.getWriter().write("success");
        return demoService.get(username);
    }

    @LagouSecurity(value ={"wangwu"} )
    @LagouRequestMapping("/test2")
    public String test2(HttpServletRequest request,HttpServletResponse response,String username) throws IOException {
        response.getWriter().write("this is only want wu");
        return demoService.get(username);
    }
    @LagouSecurity(value={"tian"})
    @LagouRequestMapping("/test3")
    public String test3(HttpServletRequest request,HttpServletResponse response,String username) throws IOException {
        response.getWriter().write("this is only tian");
        return demoService.get(username);
    }


}
